package org.xhy.sniffer.plugins.tomcat;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.xhy.sniffer.plugin.ClassEnhancePluginDefine;
import org.xhy.sniffer.interceptor.ConstructorMethodsInterceptorPoint;
import org.xhy.sniffer.interceptor.InstanceMethodsInterceptorPoint;
import org.xhy.sniffer.interceptor.StaticMethodsInterceptorPoint;

import static net.bytebuddy.matcher.ElementMatchers.*;


public abstract class TomcatRequestInstrumentation extends ClassEnhancePluginDefine {
    private static final String INTERCEPTOR = "org.xhy.sniffer.plugins.tomcat.interceptor.TomcatInterceptor";

    @Override
    protected InstanceMethodsInterceptorPoint[] getInstanceMethodsInterceptorPoints() {
        return new InstanceMethodsInterceptorPoint[]{
                new InstanceMethodsInterceptorPoint() {
                    @Override
                    public ElementMatcher<MethodDescription> getMethodsMatcher() {
                        return not(isStatic()).and(
                                nameMatches("invoke")
                        );
                    }

                    @Override
                    public String getMethodsInterceptor() {
                        return INTERCEPTOR;
                    }
                }
        };
    }

    @Override
    protected ConstructorMethodsInterceptorPoint[] getConstructorMethodsInterceptorPoints() {
        return null;
    }

    @Override
    protected StaticMethodsInterceptorPoint[] getStaticMethodsInterceptorPoints() {
        return new StaticMethodsInterceptorPoint[0];
    }

}
